home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d18 / twars.arc / COMMON.BAK next >
Text File  |  1991-04-28  |  13KB  |  644 lines

  1. { ok, to run a WWIV 3.21d program under WWIV v4.00:
  2.  
  3.   take the source to the 3.21d .chn file, edit it, and remove procedure
  4.   return.  Then, make sure this (new) common.pas is in the same directory,
  5.   and compile the 3.21d .chn to a .com file.  Say the program is "dukedom".
  6.   you compile it to dukedom.com.  Now, make sure it is in your main WWIV
  7.   v4.00 directory, and add a new chain to the wwiv 4.00 database.  For the
  8.   filename, say "dukedom %1".
  9.  
  10.   For more advanced conversion, you should go through the source, and,
  11.   wherever you find something like "'gfiles\whatever.msg'", replace it with
  12.   either "gfilespath+'whatever.msg'", or "datapath+'whatever.msg'".  You
  13.   should use gfilespath if the file is an ascii file, and datapath if the
  14.   file is a data file.  Then, of course, you have to make sure that the
  15.   files are in the correct directory.
  16. }
  17.  
  18. {$G1}{$P1}
  19.  
  20. CONST strlen=160;
  21.  
  22. TYPE str=string[strlen];
  23.      opts=(alert,smw,nomail);
  24.      userrec=record
  25.                name:string[25];
  26.                realname:string[14];
  27.                laston:string[10];
  28.                linelen:byte;
  29.                pagelen:byte;
  30.                sl:byte;
  31.                age:byte;
  32.                sex:char;
  33.                callsign:string[8];
  34.                gold:real;
  35.                option:set of opts;
  36.              end;
  37.       regs=record ax,bx,cx,dx,bp,si,di,ds,es,flags:integer; end;
  38.       smr=record
  39.            msg:str;
  40.            destin:integer;
  41.           end;
  42. var
  43.     sysopf:text[1024];
  44.     sysopffn:string[80];
  45.     gfilespath,datapath:string[80];
  46.     destin,usernum:integer;
  47.     incom,okansi,cs,so,hangup:boolean;
  48.     timeon,timeleft:real;
  49.     thisuser:userrec;
  50.     rp:regs;
  51.     i,
  52.     thisline:str;
  53.     ret,t:integer;
  54. function timer:real;
  55. var reg:record
  56.           ax,bx,cx,dx,bp,si,di,ds,es,flags:integer;
  57.         end;
  58.     h,m,s,t:real;
  59. begin
  60.   reg.ax:=44*256;
  61.   msdos(reg);
  62.   h:=(reg.cx div 256);
  63.   m:=(reg.cx mod 256);
  64.   s:=(reg.dx div 256);
  65.   t:=(reg.dx mod 256);
  66.   timer:=h*3600+m*60+s+t/100;
  67. end;
  68.  
  69. function nsl:real;
  70. begin
  71.   if timer<timeon then
  72.     timeon:=timeon-24.0*3600.0;
  73.   nsl:=timeleft-(timer-timeon);
  74. end;
  75.  
  76. function sysop1:boolean;
  77. begin
  78.   if (mem[0:1047] and 16)=0 then sysop1:=false else sysop1:=true;
  79. end;
  80.  
  81. function sysop:boolean;
  82. begin
  83.   sysop:=sysop1;
  84. end;
  85.  
  86. procedure dump;
  87. begin
  88. end;
  89.  
  90. procedure skey(var c:char);
  91. begin
  92. end;
  93.  
  94. procedure outkey(c:char);
  95. begin
  96. end;
  97.  
  98. procedure sl1(i:str);
  99. begin
  100.   writeln(sysopf,i);
  101. end;
  102.  
  103. procedure sysoplog(i:str);
  104. begin
  105.     sl1('   '+i);
  106. end;
  107.  
  108. function tch(i:str):str;
  109. begin
  110.   if length(i)>2 then i:=copy(i,length(i)-1,2) else
  111.     if length(i)=1 then i:='0'+i;
  112.   tch:=i;
  113. end;
  114.  
  115. function time:str;
  116. var reg:record
  117.           ax,bx,cx,dx,bp,si,di,ds,es,flags:integer;
  118.         end;
  119.     h,m,s:string[4];
  120. begin
  121.   reg.ax:=$2c00; intr($21,reg);
  122.   str(reg.cx shr 8,h); str(reg.cx mod 256,m); str(reg.dx shr 8,s);
  123.   time:=tch(h)+':'+tch(m)+':'+tch(s);
  124. end;
  125.  
  126. function date:str;
  127. var reg:record
  128.           ax,bx,cx,dx,bp,si,di,ds,es,flags:integer;
  129.         end;
  130.     m,d,y:string[4];
  131. begin
  132.   reg.ax:=$2a00; msdos(reg); str(reg.cx,y); str(reg.dx mod 256,d);
  133.   str(reg.dx shr 8,m);
  134.   date:=tch(m)+'/'+tch(d)+'/'+tch(y);
  135. end;
  136.  
  137. function value(I:str):integer;
  138. var n,n1:integer;
  139. begin
  140.   val(i,n,n1);
  141.   if n1<>0 then begin
  142.     i:=copy(i,1,n1-1);
  143.     val(i,n,n1)
  144.   end;
  145.   value:=n;
  146.   if i='' then value:=0;
  147. end;
  148.  
  149. function cstr(i:integer):str;
  150. var c:str;
  151. begin
  152.   str(i,c); cstr:=c;
  153. end;
  154.  
  155. function nam:str;
  156. var s:str; i:integer; tf:boolean;
  157. begin
  158.   s:=thisuser.name;
  159.   tf:=true;
  160.   for i:=1 to length(s) do
  161.     if s[i]<'A' then
  162.       tf:=true
  163.     else begin
  164.       if (s[i]<='Z') and not tf then
  165.         s[i]:=chr(ord(s[i])+32);
  166.       tf:=false;
  167.     end;
  168.   nam:=s+' #'+cstr(usernum);
  169. end;
  170.  
  171. function leapyear(yr:integer):boolean;
  172. begin
  173.   leapyear:=(yr mod 4=0) and ((yr mod 100<>0) or (yr mod 400=0));
  174. end;
  175.  
  176. function days(mo,yr:integer):integer;
  177. var d:integer;
  178. begin
  179.   d:=value(copy('312831303130313130313031',1+(mo-1)*2,2));
  180.   if (mo=2) and leapyear(yr) then d:=d+1;
  181.   days:=d;
  182. end;
  183.  
  184. function daycount(mo,yr:integer):integer;
  185. var m,t:integer;
  186. begin
  187.   t:=0;
  188.   for m:=1 to (mo-1) do t:=t+days(m,yr);
  189.   daycount:=t;
  190. end;
  191.  
  192. function daynum(dt:str):integer;
  193. var d,m,y,t,c:integer;
  194. begin
  195.   t:=0;
  196.   m:=value(copy(dt,1,2));
  197.   d:=value(copy(dt,4,2));
  198.   y:=value(copy(dt,7,2))+1900;
  199.   for c:=1985 to y-1 do
  200.     if leapyear(c) then t:=t+366 else t:=t+365;
  201.   t:=t+daycount(m,y)+(d-1);
  202.   daynum:=t;
  203.   if y<1985 then daynum:=0;
  204. end;
  205.  
  206. function dat:str;
  207. var ap,x,y:str; i:integer;
  208. begin
  209.   case daynum(date) mod 7 of
  210.     0:x:='Tue';
  211.     1:x:='Wed';
  212.     2:x:='Thu';
  213.     3:x:='Fri';
  214.     4:x:='Sat';
  215.     5:x:='Sun';
  216.     6:x:='Mon';
  217.   end;
  218.   case value(copy(date,1,2)) of
  219.     1:y:='Jan';
  220.     2:y:='Feb';
  221.     3:y:='Mar';
  222.     4:y:='Apr';
  223.     5:y:='May';
  224.     6:y:='Jun';
  225.     7:y:='Jul';
  226.     8:y:='Aug';
  227.     9:y:='Sep';
  228.     10:y:='Oct';
  229.     11:y:='Nov';
  230.     12:y:='Dec';
  231.   end;
  232.   x:=x+' '+y+' '+copy(date,4,2)+', '+cstr(1900+value(copy(date,7,2)));
  233.   y:=time; i:=value(copy(y,1,2));
  234.   if i>11 then ap:='pm' else ap:='am';
  235.   if i>12 then i:=i-12;
  236.   if i=0 then i:=12;
  237.   dat:=cstr(i)+copy(y,3,3)+' '+ap+'  '+x;
  238. end;
  239.  
  240. procedure checkhangup;
  241. begin
  242. end;
  243.  
  244. procedure getkey(var c:char); forward;
  245.  
  246. procedure prompt(i:str); forward;
  247.  
  248.  
  249. procedure ansic(c:integer);
  250. var i:str;
  251. begin
  252.   if (c=1) or (c=0) then
  253.     c:=0
  254.   else
  255.     if (c=2) then
  256.       c:=7
  257.     else
  258.       c:=c-2;
  259.   i:=#3+chr(ord('0')+c);
  260.   prompt(i);
  261. end;
  262.  
  263. procedure sdc;
  264. var f:integer;
  265. begin
  266.   ansic(0);
  267. end;
  268.  
  269.  
  270. procedure pausescr;
  271. var i:integer; cc:char;
  272. begin
  273.   ansic(3); prompt('[Pause]'); ansic(0);
  274.   getkey(cc);
  275.   for i:=1 to 7 do
  276.     prompt(#8+' '+#8);
  277. end;
  278.  
  279. procedure prompt;
  280. var c:integer; cc:char;
  281. begin
  282.   if (not hangup) then
  283.     for c:=1 to length(i) do begin
  284.       if (i[c]=#10) then
  285.         ansic(0);
  286.       write(i[c]);
  287.     end;
  288. end;
  289.  
  290. procedure print(i:str);
  291. begin
  292.   prompt(i+chr(13)+chr(10))
  293. end;
  294.  
  295. procedure nl;
  296. begin
  297.   prompt(chr(13)+chr(10))
  298. end;
  299.  
  300. procedure prt(i:str);
  301. begin
  302.   ansic(4); prompt(i); ansic(0);
  303. end;
  304.  
  305. procedure ynq(i:str);
  306. begin
  307.   ansic(7); prompt(i);
  308. end;
  309.  
  310. procedure mpl(c:integer);
  311. var n:integer; i:str;
  312. begin
  313.   if okansi then begin
  314.     ansic(6);
  315.     i:='';
  316.     for n:=1 to c do i:=i+' ';
  317.     prompt(i);
  318.     prompt(#27+'['+cstr(c)+'D');
  319.   end;
  320. end;
  321.  
  322. procedure tleft;
  323. var x,y:integer;
  324. begin
  325.   if timer<timeon then timeon:=timeon-24.0*60*60;
  326.   if (nsl<0) then begin
  327.     nl;
  328.     print('Time expired.');
  329.     hangup:=true;
  330.   end;
  331.   checkhangup;
  332. end;
  333.  
  334.  
  335. function empty:boolean;
  336. begin
  337.   rp.ax:=$0b00;
  338.   msdos(rp);
  339.   if (rp.ax and $00ff)=$00 then
  340.     empty:=true
  341.   else
  342.     empty:=false;
  343. end;
  344.  
  345. function inkey:char;
  346. var ch:char;
  347. begin
  348.   if (empty) then
  349.     inkey:=#0
  350.   else begin
  351.     rp.ax:=$0800;
  352.     msdos(rp);
  353.     inkey:=chr(rp.ax and $00ff);
  354.   end;
  355. end;
  356.  
  357.  
  358. procedure getkey;
  359. begin
  360.     rp.ax:=$0800;
  361.     msdos(rp);
  362.     c:=chr(rp.ax and $00ff);
  363. end;
  364.  
  365. procedure cls;
  366. begin
  367.   write(chr(12));
  368. end;
  369.  
  370.  
  371. function yn:boolean;
  372. var c:char;
  373. begin
  374.   if not hangup then begin
  375.     ansic(3);
  376.     repeat
  377.       getkey(c);
  378.       c:=upcase(c);
  379.     until (c='Y') or (c='N') or (c=chr(13)) or hangup;
  380.     if c='Y' then begin print('Yes'); yn:=true; end else begin print('No'); yn:=false; end;
  381.     if hangup then yn:=false;
  382.   end;
  383. end;
  384.  
  385. procedure input1(var i:str; ml:integer; tf:boolean);
  386. var cp:integer;
  387.     c:char;
  388.     r:real;
  389. begin
  390.  checkhangup;
  391.  if not hangup then begin
  392.   r:=timer;
  393.   cp:=1;
  394.   repeat
  395.     getkey(c);
  396.     if c=#1 then r:=timer;
  397.     if not tf then c:=upcase(c);
  398.     if (c>=' ') and (c<chr(127)) then
  399.       if cp<=ml then begin
  400.       i[cp]:=c;
  401.       cp:=cp+1;
  402.       write(c);
  403.     end else else case ord(c) of
  404.       8:if cp>1 then begin
  405.                c:=chr(8);
  406.                write(#8#32#8);
  407.                cp:=cp-1;
  408.              end;
  409.       21,24:while cp<>1 do begin
  410.                cp:=cp-1;
  411.                write(#8#32#8);
  412.              end;
  413.     end;
  414.     if (timer-r)>300.0 then hangup:=true;
  415.   until (c=#13) or (c=#14) or hangup;
  416.   i[0]:=chr(cp-1);
  417.   nl;
  418.  end;
  419. end;
  420.  
  421. procedure input(var i:str; ml:integer);
  422. begin
  423.   input1(i,ml,false);
  424. end;
  425.  
  426.  
  427. procedure inputl(var i:str; ml:integer);
  428. begin
  429.   input1(i,ml,true);
  430. end;
  431.  
  432. procedure onek(var c:char; ch:str);
  433. begin
  434.   repeat
  435.     getkey(c);
  436.     c:=upcase(c);
  437.   until (pos(c,ch)>0) or hangup;
  438.   if hangup then c:=ch[1];
  439.   print(''+c);
  440. end;
  441.  
  442.  
  443.  procedure wkey(var abort,next:boolean);
  444.  var cc:char;
  445.  begin
  446.     while not (empty or hangup or abort) do begin
  447.       getkey(cc);
  448.       if (cc=' ') or (cc=chr(3)) or (cc=chr(24)) or (cc=chr(11)) then
  449.         abort:=true;
  450.       if (cc=chr(14)) then begin abort:=true; next:=true; end;
  451.       if (cc=chr(19)) or (cc='P') or (cc='p') then begin
  452.         getkey(cc);
  453.       end;
  454.     end;
  455.  end;
  456.  
  457. function ctim(rl:real):str;
  458. var h,m,s:str;
  459. begin
  460.   s:=tch(cstr(trunc(rl-int(rl/60.0)*60.0)));
  461.   m:=tch(cstr(trunc(int(rl/60.0)-int(rl/3600.0)*60.0)));
  462.   h:=cstr(trunc(rl/3600.0));
  463.   if length(h)=1 then h:='0'+h;
  464.   ctim:=h+':'+m+':'+s;
  465. end;
  466.  
  467. function tlef:str;
  468. begin
  469.   tlef:=ctim(nsl);
  470. end;
  471.  
  472. function cstrr(rl:real; base:integer):str;
  473. var c1,c2,c3:integer; i:str; r1,r2:real;
  474. begin
  475.  if rl<=0.0 then cstrr:='0' else begin
  476.   r1:=ln(rl)/ln(1.0*base);
  477.   r2:=exp(ln(1.0*base)*(trunc(r1)));
  478.   i:='';
  479.   while (r2>0.999) do begin
  480.     c1:=trunc(rl/r2);
  481.     i:=i+copy('0123456789ABCDEF',c1+1,1);
  482.     rl:=rl-c1*r2;
  483.     r2:=r2/(1.0*base);
  484.   end;
  485.   cstrr:=i;
  486.  end;
  487. end;
  488.  
  489.  
  490. procedure printa1(i:str; var abort,next:boolean);
  491. var c:integer;
  492. begin
  493.  checkhangup;
  494.  if not hangup then begin
  495.   abort:=false; next:=false; c:=1;
  496.   if not empty then wkey(abort,next);
  497.   while (not abort) and (c-1<length(i)) and (not hangup) do begin
  498.     checkhangup;
  499.     if i[c]=#3 then
  500.       if i[c+1] in [#0..#8] then
  501.         if okansi then
  502.           ansic(ord(i[c+1]));
  503.     if not empty then wkey(abort,next);
  504.     if i[c]=#3 then
  505.       c:=c+1
  506.     else
  507.       write(i[c]);
  508.     c:=c+1;
  509.   end;
  510.  end else abort:=true;
  511. end;
  512.  
  513. procedure printa(i:str; var abort,next:boolean);
  514. var s:str; p,op,rp,rop,nca:integer; crend:boolean;
  515. begin
  516.   abort:=false;
  517.   crend:=(i[length(i)]=#1) and (i[length(i)-1]<>#3);
  518.   if crend then i:=copy(i,1,length(i)-1);
  519.   wkey(abort,next);
  520.   if i='' then nl;
  521.   while (i<>'') and (not abort) and (not hangup) do begin
  522.     rp:=0; nca:=thisuser.linelen-wherex-1; p:=0;
  523.     while (rp<nca) and (p<length(i)) do begin
  524.       if i[p+1]=#8 then rp:=rp-1 else
  525.         if i[p+1]=#3 then
  526.           p:=p+1
  527.         else
  528.           if (i[p+1]<>#10) then rp:=rp+1;
  529.       p:=p+1;
  530.     end;
  531.     op:=p; rop:=rp;
  532.     if (rp>=nca) and (p<length(i)) then begin
  533.       while ((not (i[p] in [' ',#8,#10])) or (i[p-1]=#3)) and (p>1) do begin
  534.         rp:=rp-1; p:=p-1;
  535.       end;
  536.       if p=1 then
  537.         if not (i[1] in [' ',#8,#10]) then begin rp:=rp-1; p:=p-1; end;
  538.     end;
  539.     if abs(rop-rp)>=(thisuser.linelen div 2) then p:=op;
  540.     s:=copy(i,1,p); delete(i,1,p);
  541.     if (s[length(s)]=' ') then s[0]:=pred(s[0]);
  542.     printa1(s,abort,next);
  543.     if ((i='') and crend) or (i<>'') or abort then
  544.       nl
  545.     else
  546.       printa1(' ',abort,next);
  547.   end;
  548. end;
  549.  
  550. procedure printacr(i:str; var abort,next:boolean);
  551. begin
  552.  if not abort then
  553.   if i[length(i)]=#1 then
  554.     printa(i,abort,next)
  555.   else
  556.     printa(i+#1,abort,next);
  557. end;
  558.  
  559. procedure pfl(fn:str; var abort:boolean; cr:boolean);
  560. var fil:text;
  561.     i:str;
  562.     next:boolean;
  563. begin
  564.     if not hangup then begin
  565.       assign(fil,fn);
  566.       {$I-} reset(fil); {$I+}
  567.       if ioresult<>0 then print('File not found.') else begin
  568.         abort:=false;
  569.         while not eof(fil) and (not abort) and (not hangup) do begin
  570.           readln(fil,i);
  571.           if cr then
  572.             printacr(i,abort,next)
  573.           else
  574.             printa(i,abort,next);
  575.         end;
  576.         close(fil);
  577.       end;
  578.       nl;nl;
  579.     end;
  580. end;
  581.  
  582. procedure printfile(fn:str);
  583. var abort:boolean;
  584. begin
  585.   pfl(fn,abort,true);
  586. end;
  587.  
  588. procedure iport;
  589. var f:text;
  590.     i:str;
  591.     n:integer;
  592. begin
  593.   assign(f,paramstr(1));
  594.   {$I-} reset(f); {$I+}
  595.   if (ioresult=0) then begin
  596.     readln(f,usernum);
  597.     readln(f,thisuser.name);
  598.     readln(f,thisuser.realname);
  599.     readln(f,thisuser.callsign);
  600.     readln(f,thisuser.age);
  601.     readln(f,thisuser.sex);
  602.     readln(f,thisuser.gold);
  603.     readln(f,thisuser.laston);
  604.     readln(f,thisuser.linelen);
  605.     readln(f,thisuser.pagelen);
  606.     readln(f,thisuser.sl);
  607.     readln(f,n);
  608.     cs:=(n=1);
  609.     readln(f,n);
  610.     so:=(n=1);
  611.     readln(f,n);
  612.     okansi:=(n=1);
  613.     readln(f,n);
  614.     incom:=(n=1);
  615.     readln(f,timeleft);
  616.     readln(f,gfilespath);
  617.     readln(f,datapath);
  618.     readln(f,i);
  619.     close(f);
  620.     sysopffn:=gfilespath+i;
  621.     assign(sysopf,sysopffn);
  622.     {$I-} append(sysopf); {$I+}
  623.     if (ioresult<>0) then begin
  624.       rewrite(sysopf);
  625.     end;
  626.   end else begin
  627.     writeln('Parameter file not found.');
  628.     halt;
  629.   end;
  630.   hangup:=false;
  631.   timeon:=timer;
  632. end;
  633.  
  634. procedure return;
  635. begin
  636.   close(sysopf);
  637.   halt;
  638. end;
  639.  
  640. procedure topscr;
  641. begin
  642. end;
  643.  
  644.